home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / PENDLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  6.2 KB  |  251 lines

  1. {**********************************************}
  2. {   TPenDialog                                 }
  3. {   Copyright (c) 1996-98 by David Berneda     }
  4. {**********************************************}
  5. {$I teedefs.inc}
  6. unit PenDlg;
  7.  
  8. interface
  9.  
  10. uses
  11.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  12.   Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, TeCanvas
  13.   {$IFDEF D1}
  14.   , TeeUpDow, Spin
  15.   {$ELSE}
  16.   , ComCtrls
  17.   {$ENDIF};
  18.  
  19. type
  20.   TPenDialog = class(TForm)
  21.     CBVisible: TCheckBox;
  22.     SEWidth: TEdit;
  23.     LWidth: TLabel;
  24.     RGStyle: TRadioGroup;
  25.     Button1: TButton;
  26.     GroupBox1: TGroupBox;
  27.     SHColor: TShape;
  28.     BColor: TButton;
  29.     Button3: TButton;
  30.     UDWidth: TUpDown;
  31.     procedure FormShow(Sender: TObject);
  32.     procedure RGStyleClick(Sender: TObject);
  33.     procedure SEWidthChange(Sender: TObject);
  34.     procedure CBVisibleClick(Sender: TObject);
  35.     procedure BColorClick(Sender: TObject);
  36.     procedure SHColorMouseUp(Sender: TObject; Button: TMouseButton;
  37.       Shift: TShiftState; X, Y: Integer);
  38.     procedure Button3Click(Sender: TObject);
  39.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  40.     procedure FormCreate(Sender: TObject);
  41.   private
  42.     { Private declarations }
  43.     CreatingForm:Boolean;
  44.     BackupPen:TChartPen;
  45.     Procedure RefreshShape;
  46.   public
  47.     { Public declarations }
  48.     ThePen:TPen;
  49.   end;
  50.  
  51. Function EditColor(AOwner:TComponent; AColor:TColor):TColor;
  52. Procedure EditChartPen(AOwner:TComponent; ChartPen:TChartPen);
  53. Procedure EditPen(AOwner:TComponent; APen:TPen);
  54.  
  55. { Show the Open Picture dialog to ask the user for a picture file }
  56. procedure TeeLoadClearImage(AOwner:TComponent; AImage:TPicture);
  57.  
  58. { Show / Hide controls in array }
  59. Procedure ShowControls(Show:Boolean; Const AControls:Array of TControl);
  60. { Enable / Disable controls in array }
  61. Procedure EnableControls(Show:Boolean; Const AControls:Array of TControl);
  62.  
  63. { Asks the user a question and returns Yes or No }
  64. Function TeeYesNo(Const Message:String):Boolean;
  65.  
  66. implementation
  67.  
  68. {$R *.DFM}
  69. Uses TeeConst,TeeProcs
  70.      {$IFDEF D3}
  71.      ,ExtDlgs
  72.      {$ENDIF}
  73.      ;
  74.  
  75. Function EditColor(AOwner:TComponent; AColor:TColor):TColor;
  76. Begin
  77.   With TColorDialog.Create(AOwner) do
  78.   try
  79.     Color:=AColor;
  80.     if Execute then AColor:=Color;
  81.   finally
  82.     Free;
  83.   end;
  84.   result:=AColor;
  85. end;
  86.  
  87. Procedure EditChartPen(AOwner:TComponent; ChartPen:TChartPen);
  88. Begin
  89.   With TPenDialog.Create(AOwner) do
  90.   try
  91.     ThePen:=ChartPen;
  92.     ShowModal;
  93.   finally
  94.     Free;
  95.   end;
  96. end;
  97.  
  98. Procedure EditPen(AOwner:TComponent; APen:TPen);
  99. Begin
  100.   With TPenDialog.Create(AOwner) do
  101.   try
  102.     ThePen:=TChartPen(APen);
  103.     ShowModal;
  104.   finally
  105.     Free;
  106.   end;
  107. end;
  108.  
  109. procedure TPenDialog.FormShow(Sender: TObject);
  110. begin
  111.   Screen.Cursor:=crDefault;
  112.   BackupPen:=TChartPen.Create(nil);
  113.   BackupPen.Assign(ThePen);
  114.   if ThePen is TChartPen then
  115.   begin
  116.     CBVisible.Checked:=TChartPen(ThePen).Visible;
  117.     BackupPen.Visible:=CBVisible.Checked;
  118.     {$IFNDEF D1}
  119.     if (Win32Platform=VER_PLATFORM_WIN32_NT) then
  120.        RGStyle.Items.Add(TeeMsg_SmallDotsPen);
  121.     if TChartPen(ThePen).SmallDots then
  122.        RGStyle.ItemIndex:=RGStyle.Items.Count-1
  123.     else
  124.     {$ENDIF}
  125.        RGStyle.ItemIndex:=Ord(ThePen.Style);
  126.   end
  127.   else
  128.   begin
  129.     CBVisible.Visible:=False;
  130.     RGStyle.ItemIndex:=Ord(ThePen.Style);
  131.   end;
  132.   UDWidth.Position:=ThePen.Width;
  133.   RGStyle.Enabled:=ThePen.Width=1;
  134.   SHColor.Cursor:=crTeeHand;
  135.   RefreshShape;
  136.   CreatingForm:=False;
  137. end;
  138.  
  139. procedure TPenDialog.RGStyleClick(Sender: TObject);
  140. begin
  141.   {$IFNDEF D1}
  142.   if (ThePen is TChartPen) and
  143.      (Win32Platform=VER_PLATFORM_WIN32_NT) and
  144.      (RGStyle.ItemIndex=RGStyle.Items.Count-1) then
  145.          TChartPen(ThePen).SmallDots:=True
  146.   else
  147.   {$ENDIF}
  148.   begin
  149.     ThePen.Style:=TPenStyle(RGStyle.ItemIndex);
  150.     if ThePen is TChartPen then
  151.        TChartPen(ThePen).SmallDots:=False;
  152.   end;
  153. end;
  154.  
  155. procedure TPenDialog.SEWidthChange(Sender: TObject);
  156. begin
  157.   if not CreatingForm then
  158.   begin
  159.     ThePen.Width:=UDWidth.Position;
  160.     RGStyle.Enabled:=ThePen.Width=1;
  161.   end;
  162. end;
  163.  
  164. procedure TPenDialog.CBVisibleClick(Sender: TObject);
  165. begin
  166.   if not CreatingForm then TChartPen(ThePen).Visible:=CBVisible.Checked;
  167. end;
  168.  
  169. procedure TPenDialog.BColorClick(Sender: TObject);
  170. begin
  171.   With ThePen do Color:=EditColor(Self,Color);
  172.   RefreshShape;
  173. end;
  174.  
  175. Procedure TPenDialog.RefreshShape;
  176. begin
  177.   BColor.Enabled:=SHColor.Visible;
  178.   SHColor.Brush.Color:=ThePen.Color;
  179. end;
  180.  
  181. procedure TPenDialog.SHColorMouseUp(Sender: TObject; Button: TMouseButton;
  182.   Shift: TShiftState; X, Y: Integer);
  183. begin
  184.   BColorClick(Self);
  185. end;
  186.  
  187. procedure TPenDialog.Button3Click(Sender: TObject);
  188. begin
  189.   ThePen.Assign(BackupPen);
  190.   if ThePen is TChartPen then
  191.   begin
  192.     TChartPen(ThePen).Visible:=BackupPen.Visible;
  193.     {$IFNDEF D1}
  194.     if Assigned(ThePen.OnChange) then 
  195.     {$ENDIF}
  196.       ThePen.OnChange(Self);
  197.   end;
  198.   ModalResult:=mrCancel;
  199. end;
  200.  
  201. procedure TPenDialog.FormClose(Sender: TObject; var Action: TCloseAction);
  202. begin
  203.   BackupPen.Free;
  204. end;
  205.  
  206. procedure TPenDialog.FormCreate(Sender: TObject);
  207. begin
  208.   CreatingForm:=True;
  209. end;
  210.  
  211. procedure TeeLoadClearImage(AOwner:TComponent; AImage:TPicture);
  212. begin
  213.   if AImage.Graphic<>nil then AImage.Assign(nil)
  214.   else
  215.   {$IFDEF D3}
  216.   With TOpenPictureDialog.Create(AOwner) do
  217.   {$ELSE}
  218.   With TOpenDialog.Create(AOwner) do
  219.   {$ENDIF}
  220.   try
  221.     Filter:=GraphicFilter(TGraphic);
  222.     {$IFNDEF D3}
  223.     DefaultExt:=TeeGetImageExtension(0);
  224.     Options:=Options+[ofHideReadOnly];
  225.     {$ENDIF}
  226.     if Execute then AImage.LoadFromFile(FileName);
  227.   finally
  228.     Free;
  229.   end;
  230. end;
  231.  
  232. Procedure ShowControls(Show:Boolean; Const AControls:Array of TControl);
  233. var t:Integer;
  234. begin
  235.   for t:=Low(AControls) to High(AControls) do AControls[t].Visible:=Show;
  236. end;
  237.  
  238. Procedure EnableControls(Show:Boolean; Const AControls:Array of TControl);
  239. var t:Integer;
  240. begin
  241.   for t:=Low(AControls) to High(AControls) do AControls[t].Enabled:=Show;
  242. end;
  243.  
  244. Function TeeYesNo(Const Message:String):Boolean;
  245. Begin
  246.   Screen.Cursor:=crDefault;
  247.   result:=MessageDlg(Message,mtConfirmation,[mbYes,mbNo],0)=mrYes;
  248. End;
  249.  
  250. end.
  251.